package com.sdna.unified;

import java.io.UnsupportedEncodingException;

import com.sdna.rpc.RPCClientMgr;
import com.sdna.rpc.RPCClient;
import com.sdna.rpc.ParameterBuilder;
import java.util.HashMap;


/**
 * @author gaoyong01
 * 用户私信服务
 * 
 * 主要对于以下2张表的操作
 * 1： 表MESSAGE_DIALOG (会话表) 会话是对于私信的一个容器。
 * 2: 表MESSAGE (私信)
 * 3：会调用到 CommonMessageService 的一些公共操作
 */

/**
  * This file is generated by GenerateServiceClient.py, SVN location:
  *     svn://192.168.90.69/i.sdo.com/sdk/trunk/unified/GenerateServiceClient.py
  *
  * Please DO NOT change this file!!! it is just a wrapper of unified service api.   
  */

public class privateMessageServiceClient {

	/*
	 * 得到用户的会话列表(分页版)
	 */
	static public String queryPersonalSessionList(Long sdid, HashMap<String, Object> parameters) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("sdid", sdid);
		if (parameters.containsKey("startIndex")) pb.add("startIndex", (Integer)parameters.get("startIndex"));
		if (parameters.containsKey("count")) pb.add("count", (Integer)parameters.get("count"));
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.queryPersonalSessionList", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 得到最新的num个别人发过我消息的会话
	 * 最新内容是我发送别人的消息不算入内
	 */
	static public String queryNewPersonalSessionList(Long sdid, int count) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("sdid", sdid);
		pb.add("count", count);
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.queryNewPersonalSessionList", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 添加用户会话
	 */
	static public String addPersonalSession(Long sdid, Long receiverid, String content) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("sdid", sdid);
		pb.add("receiverid", receiverid);
		pb.add("content", content);
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.addPersonalSession", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 删除用户会话
	 */
	static public String removePersonalSession(Long id) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("id", id);
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.removePersonalSession", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 得到有关于会话的消息
	 * 每个人都有自己的一份
	 */
	static public String queryAssociatedMessageList(String sessionId, HashMap<String, Object> parameters) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("sessionId", sessionId);
		if (parameters.containsKey("startIndex")) pb.add("startIndex", (Integer)parameters.get("startIndex"));
		if (parameters.containsKey("count")) pb.add("count", (Integer)parameters.get("count"));
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.queryAssociatedMessageList", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 添加用户私信
	 */
	static public String addPrivateMessage(Long sdid, Long receiverid, String sessionId, String content) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("sdid", sdid);
		pb.add("receiverid", receiverid);
		pb.add("sessionId", sessionId);
		pb.add("content", content);
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.addPrivateMessage", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}

	/*
	 * 删除用户私信
	 */
	static public String removePrivateMessage(Long id) throws UnsupportedEncodingException{
		ParameterBuilder pb = new ParameterBuilder();
		pb.add("id", id);
		RPCClient client = RPCClientMgr.getClient();
		try {
			return client.doRequest("privateMessageService.removePrivateMessage", pb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally {
			RPCClientMgr.restore(client);
		}
	}
}